package com.xaicode.auth.exception;

import cn.hutool.core.util.StrUtil;

import java.util.Objects;

/**
 * 对象不为空或字符串不为空
 * 
 * @date 2024/11/26
 */
public class MustNotNullOrEmptyException extends RuntimeException {

    /**
     * 匹配异常的参数
     */
    private Object errParam;

    /**
     * 匹配异常消息
     */
    private String errMsg;

    public MustNotNullOrEmptyException() {
    }

    public MustNotNullOrEmptyException(String errMsg) {
        this.errMsg = errMsg;
    }

    public MustNotNullOrEmptyException(Object errParam, String errMsg) {
        this.errParam = errParam;
        this.errMsg = errMsg;
    }

    @Override
    public String getMessage() {
        if (Objects.isNull(errParam) || StrUtil.isBlank(errMsg)) {
            return "";
        }
        if (Objects.isNull(errParam)) {
            return errMsg;
        }
        return String.format("%s: %s", errMsg, errParam);
    }

}
